﻿local L = AOSS_LOCAL_STRINGS

function AOSSControlsButtons_OnLoad(frame)
	frame.name = L.CONTROLS_BUTTONS_NAME
	frame.parent = CONTROL_PARENT
	AOSS_AddCategory(frame)
	
	ShowExampleButton("UIPanelButtonTemplate");
end

function ButtonsDropDown_Initialize(level)   	
	local infos = { 
		"UIPanelButtonTemplate", 
		"UIPanelButtonGrayTemplate", 
		"UIPanelCloseButton"
		};	
			
	UIDropDownMenu_AddButtons(infos, ButtonsDropDownItem_Click);		
end

function ButtonsDropDownItem_Click(self)	   
   local value = self:GetID();
   local dropdown = ButtonsDropDown;
   UIDropDownMenu_SetSelectedID(dropdown, value, 1);
         
   ShowExampleButton(self:GetText());      
end

function ShowExampleButton(name)
   if (lastButton) then
		lastButton:Hide();
   end

   local frame = getglobal(name);
  
   if (frame == nil) then				
	   if (name=="UIPanelCloseButton") then
			frame = CreateButton(name, name.."Example", false);   
	   else
			frame = CreateButton(name, name.."Example", true);
	   end
   end
   
   frame:Show();
   lastButton = frame;	
end

function CreateButton(template, name, needSize)      
   local frame = CreateFrame("Button", name, AOSSControlsButtons, template);
   frame:SetPoint("CENTER", ButtonsDropDown, "RIGHT", 60, 2);   
   frame:SetText("Example");
   if (needSize) then
		frame:SetWidth(110);
		frame:SetHeight(30);   
	end
	
   if (frame:GetScript("OnClick")) then
	frame:SetScript("OnClick", nil);
   end
   
   return frame;
end
